package com.xy.hms.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @author xiaye
 * @create 2020-05-07-11:48
 */
public class Sms {

        public static void main(String[] args) {
            //连接阿里云
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4G9VkZQT4HepNF2TaVFp", "wOax6VduAUpTvfVbH141blAWZihd15");
            IAcsClient client = new DefaultAcsClient(profile);

            //构建请求
            CommonRequest request = new CommonRequest();
            request.setMethod(MethodType.POST);
            request.setDomain("dysmsapi.aliyuncs.com");
            request.setVersion("2017-05-25");
            request.setAction("SendSms");

            //自定义参数
//            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", "15190632656");
            try {
                CommonResponse response = client.getCommonResponse(request);
                System.out.println(response.getData());
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }

}
